package top.mingtea.propertymannagement.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.mingtea.propertymannagement.pojo.proprietor;
import top.mingtea.propertymannagement.service.proprietorService;

import java.util.List;

@RestController
@RequestMapping("/proprietor")
public class proprietorController {
    @Autowired
    private final proprietorService proprietorService;

    public proprietorController(proprietorService proprietorService) {
        this.proprietorService = proprietorService;
    }

    @GetMapping("/getlist")
    public List<proprietor> getAll() {
        return proprietorService.getAll();
    }

    @PostMapping("/add")
    public void add(@RequestBody proprietor proprietor) {
        proprietorService.add(proprietor);
    }

    @DeleteMapping("/remove/{id}")
    public void remove(@PathVariable("id") String id) {
        proprietorService.remove(id);
    }

    @PutMapping("/update")
    public void update(@RequestBody proprietor proprietor) {
        proprietorService.update(proprietor);
    }

    @PostMapping("/login")
    public boolean login(@RequestParam String username, @RequestParam String password) {
        return proprietorService.dologin(username, password);
    }

    @GetMapping("/currentuser")
    public proprietor returnCurrentuser(@RequestParam String username) {
        return proprietorService.returnCurrentuser(username);
    }

    @GetMapping("/{id}")
    public proprietor returnProprietorbyId(@PathVariable String id) {
        return proprietorService.returnProprietorbyId(id);
    }
}
